package com.wjx.admin_provider.controller;


import com.wjx.admin_provider.dao.AppointmentDao;
import com.wjx.admin_provider.dao.RatingDao;
import com.wjx.admin_provider.dao.ServeDao;
import com.wjx.admin_provider.dao.UserDao;
import com.wjx.admin_provider.model.Appointment;
import com.wjx.admin_provider.model.Rating;
import com.wjx.admin_provider.model.Serve;
import com.wjx.admin_provider.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class AdminController {
    @Autowired
    private AppointmentDao appointmentDao;
    @Autowired
    private ServeDao serveDao;
    @Autowired
    private UserDao userDao;
    @Autowired
    private RatingDao ratingDao;

    @PostMapping("/admin-queryAllAppointment")
    public List<Appointment> queryAllAppointment(){
        return appointmentDao.queryAllAppointment();
    }
    @PostMapping("/admin-queryServiceById")
    public Serve queryServiceById(@RequestParam("id") int id){
        return serveDao.queryServiceById(id);
    }
    @PostMapping("/admin-queryUserById")
    public User queryUserById(@RequestParam("id") int id){
        return userDao.queryUserById(id);
    }
    @PostMapping("/admin-queryAppointmentById")
    public Appointment queryAppointmentById(@RequestParam("id") int id){
        return appointmentDao.queryAppointmentById(id);
    }
    @PostMapping("/admin-queryServiceByName")
    public Serve queryServiceByName(@RequestParam("serviceName") String serviceName){
        return serveDao.queryServiceByName(serviceName);
    }
    @PostMapping("/admin-selectUserByUsername")
    public User selectUserByUsername(@RequestParam("username") String username) {
        return userDao.selectUserByUsername(username);
    }
    @PostMapping("/admin-updateAppointmentById")
    public int updateAppointmentById(@RequestParam("id") int id,@RequestParam("userId") int userId,
                                     @RequestParam("serviceId") int serviceId, @RequestParam("appointmentTime") String appointmentTime,
                                     @RequestParam("appointmentLocation")  String appointmentLocation, @RequestParam("phone") String phone,
                                     @RequestParam("status") String status,@RequestParam("lastUpdatedTime") String lastUpdatedTime){
        Appointment appointment = new Appointment(id,userId,serviceId,appointmentTime,
                appointmentLocation,phone,status,lastUpdatedTime);
        return appointmentDao.updateAppointmentById(appointment);
    }
    @PostMapping("/admin-deleteRatingByAppointmentId")
    public int deleteRatingByAppointmentId(@RequestParam("id") int id){
        return ratingDao.deleteRatingByAppointmentId(id);
    }
    @PostMapping("/admin-deleteAppointmentById")
    public int deleteAppointmentById(@RequestParam("id") int id){
        return appointmentDao.deleteAppointmentById(id);
    }
    @PostMapping("/admin-queryAppointmentByUserId")
    public List<Appointment> queryAppointmentByUserId(@RequestParam("id") int id){
        return appointmentDao.queryAppointmentByUserId(id);
    }
    @PostMapping("/admin-queryAppointmentByServiceId")
    public List<Appointment> queryAppointmentByServiceId(@RequestParam("id") int id){
        return appointmentDao.queryAppointmentByServiceId(id);
    }
    @PostMapping("/admin-queryLikeAppointment")
    public List<Appointment> queryLikeAppointment(@RequestParam("keyword") String keyword){
        return appointmentDao.queryLikeAppointment(keyword);
    }
    @PostMapping("/admin-queryAllUser")
    public List<User> queryAllUser(){
        return userDao.queryAllUser();
    }
    @PostMapping("/admin-queryLikeUsername")
    public List<User> queryLikeUsername(@RequestParam("keyword") String keyword){
        return userDao.queryLikeUsername(keyword);
    }
    @PostMapping("/admin-updateUserById")
    public int updateUserById(@RequestParam("id") int id,
                              @RequestParam("username") String username,
                              @RequestParam("password") String password,
                              @RequestParam("authority") String authority){
        return userDao.updateUserById(new User(id,username,password,authority));
    }
    @PostMapping("/admin-deleteAppointmentByUserId")
    public int deleteAppointmentByUserId(@RequestParam("id") int id){
        return appointmentDao.deleteAppointmentByUserId(id);
    }
    @PostMapping("/admin-deleteRatingByUserId")
    public int deleteRatingByUserId(@RequestParam("id") int id){
        return ratingDao.deleteRatingByUserId(id);
    }
    @PostMapping("/admin-deleteUserById")
    public int deleteUserById(@RequestParam("id") int id){
        return userDao.deleteUserById(id);
    }
    @PostMapping("/admin-showService")
    public List<Serve> showService(){
        return serveDao.queryAllService();
    }
    @PostMapping("/admin-search")
    public List<Serve> search( @RequestParam("keyword") String keyword){
        return serveDao.queryLikeService(keyword);
    }
    @PostMapping("/admin-updateServiceById")
    public int updateServiceById(@RequestParam("id") int id,@RequestParam("name") String name,
                                 @RequestParam("description") String description,
                                 @RequestParam("price")double  price){
        return serveDao.updateServiceById(new Serve(id,name,description,price));
    }
    @PostMapping("/admin-deleteAppointmentByServiceId")
    public int deleteAppointmentByServiceId(@RequestParam("id") int id){
        return appointmentDao.deleteAppointmentByServiceId(id);
    }
    @PostMapping("/admin-deleteRatingByServiceId")
    public int deleteRatingByServiceId(@RequestParam("id") int id){
        return ratingDao.deleteRatingByServiceId(id);
    }
    @PostMapping("/admin-deleteServiceById")
    public int deleteServiceById(@RequestParam("id") int id){
        return serveDao.deleteServiceById(id);
    }
    @PostMapping("/admin-insertService")
    public int insertService(@RequestParam("name") String name,@RequestParam("description")  String description,
                      @RequestParam("price") double price){
        return serveDao.insertService(new Serve(name,description,price));
    }
    @PostMapping("/admin-queryAllRating")
    public List<Rating> queryAllRating(){
        return ratingDao.queryAllRating();
    }
    @PostMapping("/admin-queryRatingByUserId")
    public List<Rating> queryRatingByUserId(@RequestParam("id") int id){
        return ratingDao.queryRatingByUserId(id);
    }
    @PostMapping("/admin-queryRatingByServiceId")
    public List<Rating> queryRatingByServiceId(@RequestParam("id") int id){
        return ratingDao.queryRatingByServiceId(id);
    }
    @PostMapping("/admin-queryLikeRating")
    public List<Rating> queryLikeRating(@RequestParam("keyword") String keyword){
        return ratingDao.queryLikeRating(keyword);
    }
    @PostMapping("/admin-deleteRatingById")
    public int deleteRatingById(@RequestParam("id") int id){
        return ratingDao.deleteRatingById(id);
    }
    @PostMapping("/admin-register")
    public int register(@RequestParam("username") String username,
                        @RequestParam("password") String password,
                        @RequestParam("authority")String authority){
        return userDao.addUser(new User(username,password,authority));
    }
}
